package Demo1;

import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 34255
 * Date: 2024-06-21
 * Time: 9:18
 */
public class Test {
    public static void main(String[] args) {
        int[][] array = new int[3][];//这里我们只指定行大小，当并没有具体指明列大小，也就是前面提到的定义方式
        array[0] = new int[3];
        array[1] = new int[2];
        array[2] = new int[1];
        System.out.println(array.length);
        System.out.println(array[0].length);
        System.out.println(array[1].length);
        System.out.println(array[2].length);
    }
    public static void main5(String[] args) {
        int[][] array = {{1,2,3},{2,3,4}};//定义了一个2行3列的二维数组
        System.out.println(array[0]);
        System.out.println(array[1]);
        System.out.println(array.length);
        System.out.println(array[0].length);
        System.out.println(array[1].length);
    }
    public static void main4(String[] args) {
        int[][] array = {{1,2,3},{2,3,4}};
        System.out.println(Arrays.toString(array));

        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array[i].length; j++) {
                System.out.print(array[i][j] + " ");
            }
            System.out.println();
        }

        for (int arr[]:array) {
            for (int x:arr) {
                System.out.print(x + " ");
            }
            System.out.println();
        }

        System.out.println(Arrays.deepToString(array));
    }
    public static void main3(String[] args) {
        int[][] array1 = {{1,2,3},{2,3,4}};
        int[][] array2 = new int[2][3];
        int[][] array3 = new int[][]{{1,2,3},{2,3,4}};
        int[][] array4 = new int[2][];
//        int[][] array5 = new int[][];
        System.out.println(Arrays.deepToString(array3));
        System.out.println(array3.length);
        System.out.println(array3[0].length);
    }
    public static void main2(String[] args) {
        int[] array = new int[]{1,2,3,4,5,6};
        Arrays.toString(array);
    }
    public static void func(Object obj){//发生向上转型
        if(obj instanceof String){//判断obj这个引用的对象类型是否为String
            String str = (String)obj;//对obj类型强转，父类类型变为子类类型，发生向下转型，String类型变量进行接收
            //...
        }
    }
    public static void main1(String[] args) {
        int[] array = new int[]{1,2,3,4,5,6};
        for (int value:array) {
            System.out.print(value + " ");
        }
        System.out.println();
    }
}
